# pip install xlrd
# pip install pyautocad
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
    =============================
    Author: DalNur
    Email: liyang@alu.hit.edu.cn
    =============================
"""
import time
from pyautocad import Autocad, APoint, aDouble
from pyautocad import Autocad

acad = Autocad(create_if_not_exists = True)
acad.prompt("Hello! AutoCAD from pyautocad.")
print(acad.doc.Name)
time.sleep(5)
# import comtypes.client
#
# try:
#     acad = comtypes.client.GetActiveObject('AutoCAD.Application', dynamic=True)
# except WindowsError:
#     acad = comtypes.client.CreateObject('AutoCAD.Application', dynamic=True)
#     acad.Visible = True
import xlrd
a=xlrd.open_workbook(r"D:\ca.xlsx")
work_book = xlrd.open_workbook(r"D:\ca.xlsx")
sheet_1 = work_book.sheet_by_index(0)
print(sheet_1)
i1= sheet_1.cell_value(1,0)
i2= sheet_1.cell_value(2,0)
i3= sheet_1.cell_value(3,0)
print(i1,i2,i3)
insertionPnt = APoint(i1, 0)
RetVal = acad.model.InsertBlock(insertionPnt, r"D:\ca.dwg", 1, 1, 1, 0 )
time.sleep(2)
insertionPnt = APoint(i2, 0)
RetVal = acad.model.InsertBlock(insertionPnt, r"D:\ca.dwg", 1, 1, 1, 0 )
time.sleep(2)
insertionPnt = APoint(i3, 0)
RetVal = acad.model.InsertBlock(insertionPnt, r"D:\ca.dwg", 1, 1, 1, 0 )

textString = "电线杆"
insertPnt = APoint(4000+i1, 1000)
height = 250
textObj = acad.model.AddText(textString, insertPnt, height)
time.sleep(2)
insertPnt = APoint(4000+i2, 1000)
height = 250
textObj = acad.model.AddText(textString, insertPnt, height)
time.sleep(2)
insertPnt = APoint(4000+i3, 1000)
height = 250
textObj = acad.model.AddText(textString, insertPnt, height)
